﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using SmsVotes.DataAccess;

namespace SmsVotes.SmsVoting
{
    /// <summary>
    /// Контрол запуска голосования
    /// </summary>
    public partial class Votes : CommandControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindVotes();
            }
        }

        protected void lvVotes_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName.Equals(COMMAND_VOTEDELETE, StringComparison.InvariantCultureIgnoreCase))
            {
                var vote = VoteManager.GetByID(Convert.ToInt32(e.CommandArgument));                
                VoteManager.Delete(vote);
                VoteManager.Save();
                BindVotes();
            }

        }
        private void BindVotes()
        {
            lvVotes.DataSource = VoteManager.GetAll(Page.User.Identity.Name);
            lvVotes.DataBind();                
        }
    }
}